home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 25 / AACD 25.iso / AACD / Magazine / Online / QMail / source / timeoutwrite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-15  |  489 b   |  26 lines

  1. #include "timeoutwrite.h"
  2. #include "select.h"
  3. #include "error.h"
  4. #include "readwrite.h"
  5.  
  6. int timeoutwrite(fdt,buf,len) int fdt; char *buf; int len;
  7. {
  8.   fd_set wfds;
  9.   struct timeval tv;
  10.   int fd;
  11.  
  12.   tv.tv_sec = (fdt >> 10);
  13.   tv.tv_usec = 0;
  14.  
  15.   fd = (fdt & 1023);
  16.   FD_ZERO(&wfds);
  17.   FD_SET(fd,&wfds);
  18.  
  19.   if (select(fd + 1,(fd_set *) 0,&wfds,(fd_set *) 0,&tv) == -1) return -1;
  20.   if (FD_ISSET(fd,&wfds)) return write(fd,buf,len);
  21.  
  22.   shutdown(fd,1);
  23.   errno = error_timeout;
  24.   return -1;
  25. }
  26.